# -*- coding: utf-8 -*-
##
## $Id: bfe_title_brief.py,v 1.14 2008/04/11 06:40:05 jerome Exp $
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibFormat element - Prints short title
"""
__revision__ = "$Id: bfe_title_brief.py,v 1.14 2008/04/11 06:40:05 jerome Exp $"

def format_element(bfo, highlight="no", multilang='no', link_to_record='no'):

    """
    Prints a short title, suitable for brief format.

    @param highlight highlights the words corresponding to search query if set to 'yes'
    @param link_to_record wheteher the title should be active link to record
    """

##    if multilang == 'yes':
##        if bfo.lang == 'fr':
##            title = bfo.field('246_1a')
##        else:
##            title = bfo.field('24500a')
##    else:
##        title = bfo.field('24500a')
    title = bfo.field('24500a')
    title_alt = bfo.field('24633a')

    out = title
    if len(title_alt) > 0:
        out += " (" + title_alt + ")"

    #Try to display 'Conference' title if other titles were not found
    if out == '':
        out += bfo.field('111__a')

    if highlight == 'yes':
        from invenio import bibformat_utils
        out = bibformat_utils.highlight(out, bfo.search_pattern,
                                        prefix_tag="<span style='font-weight: bolder'>",
                                        suffix_tag='</style>')
    if link_to_record == "yes":
    	from invenio.config import CFG_SITE_URL
    	import os
    	out = "<a href='%s'>%s</a>"  % (os.path.join(CFG_SITE_URL, "record/%d?ln=%s"%(bfo.recID, bfo.lang)), out) 

    return out
    
def escape_values(bfo):
    """
    Called by BibFormat in order to check if output of this element
    should be escaped.
    """
    return 0
    
if __name__ == "__main__":
	from invenio.bibformat_engine import BibFormatObject
	print format(BibFormatObject(1), link_to_record='yes') 

